package com.bj58.groupbuy.action.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PatternUtil {

	
	
	/**匹配是否包含中文
	 * @param content
	 * @return
	 */
	public static boolean hasContainsChinese(String content){
		Pattern pattern=Pattern.compile("[\\u4e00-\\u9fa5]");
		Matcher matcher=pattern.matcher(content);
		return matcher.find();
	}
	
	
	/**是否包含英文
	 * @param content
	 * @return
	 */
	public static boolean hasContainsEn(String content){
		Pattern pattern=Pattern.compile("[\\[A-Za-z\\]]");
		Matcher matcher=pattern.matcher(content);
		return matcher.find();
	}
	
	
	/**是否是日期 (yyyy-MM-dd)
	 * @param content
	 * @return
	 */
	public static boolean isDate(String content){
		
		Pattern pattern=Pattern.compile("[0-9]{4}-[0-9]{2}-[0-9]{2}");
		Matcher matcher=pattern.matcher(content);
		return matcher.find();
	}
	
	
	/**是否只含有数字和小数点 (仅一个小数点)
	 * @param content
	 * @return
	 */
	public static boolean onlyHasNum (String content){
		Pattern pattern=Pattern.compile("^([0-9]{1,}\\.[0-9]{1,}|[0-9]{1,})$");
		Matcher matcher=pattern.matcher(content);
		return matcher.find();
	}
	
	
	/**用户名校验 （中文、英文、数字、下划线)
	 * @param content
	 * @return
	 */
	public static boolean checkUserName (String content){
		 String regEx = "^[\\w|\\u4E00-\\u9FA5|-]+$";
		 Pattern pa = Pattern.compile(regEx);
		 Matcher ma = pa.matcher(content);
		 if(ma.matches()){
			 return true;
		 }else{
			 return false;
		 }
	}
	
	
}
